using ASP;
using HoWave.Common;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class HL_Admin__Admin_AdminPassword : Admin, IRequiresSessionState
{
	protected Literal AdminName;
	protected TextBox OldPassword;
	protected TextBox PassWord1;
	protected TextBox PassWord2;
	protected CompareValidator CompareValidator1;
	protected RequiredFieldValidator RequiredFieldValidator1;
	protected Button UpdateButton;
	private int AdminID = 0;
	private AdminBll _adminbll = null;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected AdminBll m_adminbll
	{
		get
		{
			AdminBll adminbll;
			if (this._adminbll == null)
			{
				this._adminbll = new AdminBll(this.conn);
				adminbll = this._adminbll;
			}
			else
			{
				adminbll = this._adminbll;
			}
			return adminbll;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.AdminID = Fetch.GetID("Admin_ID");
		if (this.AdminID > 0)
		{
			if (!base.admin.CheckSuperAdmin())
			{
				this.WriteErrMsg("", "只有超级管理员才有权修改他人密码！", "");
			}
			DataTable adminByAdminID = this.m_adminbll.GetAdminByAdminID(this.AdminID);
			if (adminByAdminID.Rows.Count == 1)
			{
				this.AdminName.Text = adminByAdminID.Rows[0]["UserName"].ToString();
			}
			else
			{
				this.WriteErrMsg("", "找不到该管理员帐号！", "");
			}
		}
		else
		{
			this.AdminID = base.admin.AdminID;
			this.AdminName.Text = base.admin.AdminName;
		}
	}
	protected void UpdateButton_Click(object sender, EventArgs e)
	{
		if (this.PassWord1.Text == this.PassWord2.Text)
		{
			string newPassWord = this.HTMLEncode(this.PassWord1.Text);
			string oldPassWord = this.HTMLEncode(this.OldPassword.Text);
			int num = this.m_adminbll.ChangePassword(this.AdminID, oldPassWord, newPassWord);
			if (num == 0)
			{
				this.WriteSuccessMsg("", "修改密码成功！", "");
			}
			else
			{
				if (num == 1)
				{
					this.WriteErrMsg("", "管理员不存在，修改密码不成功！", "");
				}
				else
				{
					if (num == 2)
					{
						this.WriteErrMsg("", "旧密码不正确，修改密码不成功！", "");
					}
					else
					{
						this.WriteErrMsg("", "修改密码不成功，未知错误！", "");
					}
				}
			}
		}
		else
		{
			this.WriteErrMsg("", "两次输入新密码不相同，请重新再输入!", "");
		}
	}
}
